Thinker

A thinker is an instance of a large number of diverse structures in the Doom engine which are used to implement per-tic scheduled actions within the game world. Thinkers are linked into a global which is iterated down once per tic, giving each object a turn at running its logic for that time slice. This is a very basic implementation of a system.

Types of thinkers
The following types of objects in the game world are implemented as thinkers in the original game engine:
 * Moving floors and ceilings: doors, lifts, crushing ceilings, etc.
 * Map objects
 * Sector lighting effects

Hexen adds many new types of thinkers in its customization of the Doom engine:
 * ACS scripts
 * Waggling floor effects
 * Pillars
 * Earthquakes
 * Polyobjects

Source ports may significantly expand the scope of thinkers to include new effects.

Pseudo-inheritance
Though Doom was written in the, which is not inherently , thinkers utilize a technique common in C programming called pseudo-inheritance. Every type of structure which behaves as a thinker contains a instance as the first member in its definition. This allows pointers to any of the various descendant types, such as, to be cast to and from a pointer to. Each thinker contains a pointer to a function to be executed every tic that is specific to its derived type, such as for. Testing the value of this function to determine the true type of a instance is used as a rudimentary form of.

As a result of the architectural similarity, most C++ source ports translate this idiom into a full class hierarchy - this is the case for both ZDoom and the Eternity Engine.

Referential integrity
The original engine does not implement any form of, and therefore it is possible for objects which have been removed from the list and freed to be referenced or modified afterward, resulting in arbitrary or "undefined" behavior, which may lead to corruption of other thinkers or the thinker list itself, and may eventually lead to a crash. Lost souls are particularly prone to issues related to this problem because when they become invisible at the end of their death sequence, they free themselves, causing any monsters still angry at them to possibly continue to reference invalid memory.

The Boom source port was the first implementation to correct this flaw via addition of reference counting. Some later ports have replaced the reference counting scheme with full-scale.

Language standard conflicts
The scheme used to cast structure pointers back to their true type from  is illegal in the current  language standard. This means that modern C language compilers may not generate valid code given the Doom source code unless special command line switches are provided (such as for ). This is true in particular when high levels of optimization are requested from the compiler.